/**
 * Initialize your data structure here.
 */
class MapSum {

    has: { [k: string]: number } = {}

    static createNew() {
        return new MapSum()
    }

    insert(key: string, val: number) {
        this.has[key] = val
    }

    sum(prefix: string) {

        return Object.keys(this.has)
            .filter(key => key.startsWith(prefix))
            .reduce((s, key) => s + this.has[key], 0)
    }

};


// var obj = Object.create(MapSum).createNew()
// obj.insert('apple', 5)
// console.log(obj.sum('ap'));
